// 组件接口
class TextMessage{
  constructor(message) { 
    this.message = message;
  }

  getText() { 
    return this.message;
  }
}

// 闭包高阶函数风格 HTML
function HTMLDecorator(BaseClass) { 
  return class extends BaseClass{
    getText() { 
      const msg = super.getText();
      return `<div>${msg}</div>`
    }
  }
}

// 闭包高阶函数风格 加密
function EncryptDecorator(BaseClass) { 
  return class extends BaseClass{
    getText() { 
      const msg = super.getText();
      // 倒序加密
      return this.encrypt(msg);
    }
    encrypt(msg) { 
      return msg.split("").reverse().join("");
    }
  }
}

// 使用装饰器高阶函数
let DecoratorClass = HTMLDecorator(TextMessage);
DecoratorClass = EncryptDecorator(DecoratorClass);

const messageInstance = new DecoratorClass("Hello Typescript");

console.log(messageInstance.getText());